﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMeterParamFrame.Model.DIValueConverters
{
    /// <summary>
    /// 公共假日日期及日时段表号转换
    /// </summary>
    class Converter_JiaRi : IDIDataConverter
    {
        static uint MIN = uint.Parse("04030001", System.Globalization.NumberStyles.AllowHexSpecifier);
        static uint MAX = uint.Parse("040300FE", System.Globalization.NumberStyles.AllowHexSpecifier);


        public bool CanConverter(string di)
        {
            uint udi = uint.Parse(di, System.Globalization.NumberStyles.AllowHexSpecifier);

            return (udi >= MIN && udi <= MAX);
        }

        public string ConvertToUI(string di, string lowValue)
        {
            string newValue = lowValue.Substring(0, 2) + "-" +
                lowValue.Substring(2, 2) + "-" +
                lowValue.Substring(4, 2) + " " +
                lowValue.Substring(6, 2);
            return newValue;
        }

        public string ConvertToLow(string di, string uiValue)
        {
            string[] datas = uiValue.Split(new string[] { "-", " " }, StringSplitOptions.RemoveEmptyEntries);
            string newValue = null;

            for (int i = 0; i < 4; i++)
            {
                newValue += datas[i].PadLeft(2, '0');
            }
            return newValue;
        }

        public bool ValidateValue(string di, string value)
        {
            throw new NotImplementedException();
        }
    }
}
